#!/usr/bin/python
import os, pygame
from pygame.locals import *


class GuifaImage:
    def __init__(self):
        self.imagedic = {
            "blue_summoner.png":self.loadimage_colorkey("blue_summoner.png"),
            "blue_illusionist.png":self.loadimage_colorkey("blue_illusionist.png"),
            "blue_forcefielder.png":self.loadimage_colorkey("blue_forcefielder.png"),
            "blue_sceptre.png":self.loadimage_colorkey("blue_sceptre.png"),
            "blue_necromancer.png":self.loadimage_colorkey("blue_necromancer.png"),
            "blue_soothsayer.png":self.loadimage_colorkey("blue_soothsayer.png"),
            "blue_sorcerer.png":self.loadimage_colorkey("blue_sorcerer.png"),

            "brown_summoner.png":self.loadimage_colorkey("brown_summoner.png"),
            "brown_illusionist.png":self.loadimage_colorkey("brown_illusionist.png"),
            "brown_forcefielder.png":self.loadimage_colorkey("brown_forcefielder.png"),
            "brown_sceptre.png":self.loadimage_colorkey("brown_sceptre.png"),
            "brown_necromancer.png":self.loadimage_colorkey("brown_necromancer.png"),
            "brown_soothsayer.png":self.loadimage_colorkey("brown_soothsayer.png"),
            "brown_sorcerer.png":self.loadimage_colorkey("brown_sorcerer.png"),

            "green_summoner.png":self.loadimage_colorkey("green_summoner.png"),
            "green_illusionist.png":self.loadimage_colorkey("green_illusionist.png"),
            "green_forcefielder.png":self.loadimage_colorkey("green_forcefielder.png"),
            "green_sceptre.png":self.loadimage_colorkey("green_sceptre.png"),
            "green_necromancer.png":self.loadimage_colorkey("green_necromancer.png"),
            "green_soothsayer.png":self.loadimage_colorkey("green_soothsayer.png"),
            "green_sorcerer.png":self.loadimage_colorkey("green_sorcerer.png"),

            "yellow_summoner.png":self.loadimage_colorkey("yellow_summoner.png"),
            "yellow_illusionist.png":self.loadimage_colorkey("yellow_illusionist.png"),
            "yellow_forcefielder.png":self.loadimage_colorkey("yellow_forcefielder.png"),
            "yellow_sceptre.png":self.loadimage_colorkey("yellow_sceptre.png"),
            "yellow_necromancer.png":self.loadimage_colorkey("yellow_necromancer.png"),
            "yellow_soothsayer.png":self.loadimage_colorkey("yellow_soothsayer.png"),
            "yellow_sorcerer.png":self.loadimage_colorkey("yellow_sorcerer.png"),
            
            "blue_summons.png":self.loadimage_colorkey("blue_summons.png"),
            "brown_summons.png":self.loadimage_colorkey("brown_summons.png"),
            "green_summons.png":self.loadimage_colorkey("green_summons.png"),
            "yellow_summons.png":self.loadimage_colorkey("yellow_summons.png"),
            
            "corpse_summoner.png":self.loadimage_colorkey("corpse_summoner.png"),
            "corpse_illusionist.png":self.loadimage_colorkey("corpse_illusionist.png"),
            "corpse_forcefielder.png":self.loadimage_colorkey("corpse_forcefielder.png"),
            "corpse_necromancer.png":self.loadimage_colorkey("corpse_necromancer.png"),
            "corpse_soothsayer.png":self.loadimage_colorkey("corpse_soothsayer.png"),
            "corpse_sorcerer.png":self.loadimage_colorkey("corpse_sorcerer.png"),
            
            "resurgence_flag.png":self.loadimage_colorkey("resurgence_flag.png"),
            "clone_flag.png":self.loadimage_colorkey("clone_flag.png"),
            "corpse_flag.png":self.loadimage_colorkey("corpse_flag.png"),
            "movement_flag.png":self.loadimage_colorkey("movement_flag.png"),
            "attack_flag.png":self.loadimage_colorkey("attack_flag.png"),
            "enchantment_flag.png":self.loadimage_colorkey("enchantment_flag.png"),
            "enchantment_ad_flag.png":self.loadimage_colorkey("enchantment_ad_flag.png"),
            "forcefield_flag.png":self.loadimage_colorkey("forcefield_flag.png"),
            "seal_flag.png":self.loadimage_colorkey("seal_flag.png"),

            "skill_clone_na.png":self.loadimage("skill_clone_na.png"),
            "skill_clone.png":self.loadimage("skill_clone.png"),
            "skill_crush_ad_na.png":self.loadimage("skill_crush_ad_na.png"),
            "skill_crush_ad.png":self.loadimage("skill_crush_ad.png"),
            "skill_enchantment_ad_na.png":self.loadimage("skill_enchantment_ad_na.png"),
            "skill_enchantment_ad.png":self.loadimage("skill_enchantment_ad.png"),
            "skill_seal.png":self.loadimage("skill_seal.png"),
            "skill_seal_na.png":self.loadimage("skill_seal_na.png"),
            "skill_exchange_na.png":self.loadimage("skill_exchange_na.png"),
            "skill_exchange.png":self.loadimage("skill_exchange.png"),
            "skill_resurgence_ad_na.png":self.loadimage("skill_resurgence_ad_na.png"),
            "skill_resurgence_ad.png":self.loadimage("skill_resurgence_ad.png"),
            "skill_resurgence_na.png":self.loadimage("skill_resurgence_na.png"),
            "skill_resurgence.png":self.loadimage("skill_resurgence.png"),
            "skill_summon_ad_na.png":self.loadimage("skill_summon_ad_na.png"),
            "skill_summon_ad.png":self.loadimage("skill_summon_ad.png"),
            "skill_summon_na.png":self.loadimage("skill_summon_na.png"),
            "skill_summon.png":self.loadimage("skill_summon.png"),
            "skill_dismember.png":self.loadimage("skill_dismember.png"),
            "skill_dismember_na.png":self.loadimage("skill_dismember_na.png"),

            "cur.png":self.loadimage_colorkey("cur.png"),
            "cur2.png":self.loadimage_colorkey("cur2.png"),
            "cur3.png":self.loadimage_colorkey("cur3.png"),

            "button_cancel.png":self.loadimage("button_cancel.png"),
            "board.png":self.loadimage("board.png")
        }

    def loadimage( self, name ):

        fullname = os.path.join( "./data", name )

        try:
            image = pygame.image.load( fullname )
        except pygame.error, message:
            print "Cannot load image:", fullname
            raise SystemExit, message

        # To speed things up, convert the images to SDL's internal format.
        image = image.convert()

        # Return the image
        return image

    def loadimage_colorkey( self, name ):
        image = self.loadimage( name )

        # Set color key
        colorkey = image.get_at( (0,0) )
        image.set_colorkey( colorkey, RLEACCEL )

        # Return the image
        return image

    def get_image(self, name):
        return self.imagedic[name]

if __name__ == "__main__":
    test = GuifaImage()
